package v1

// ExecutionSpec 定义了容器的执行细节,不止这些字段。
type ExecutionSpec struct {
	Image   string   `json:"image" yaml:"image" validate:"required"`
	Command []string `json:"command,omitempty" yaml:"command,omitempty"`
	Args    []string `json:"args,omitempty" yaml:"args,omitempty"`
	Env     []EnvVar `json:"env,omitempty" yaml:"env,omitempty"`
	//
	Ports     []PortSpec   `json:"ports,omitempty" yaml:"ports,omitempty" validate:"dive"` // 深入到每个切片中去验证
	Resources ResourceSpec `json:"resources,omitempty" yaml:"resources,omitempty"`
	// 定义需要挂载到此容器的卷。
	VolumeMounts []VolumeMountSpec `json:"volumeMounts,omitempty" yaml:"volumeMounts,omitempty" validate:"dive"`
}

// EnvVar 定义了一个环境变量。
type EnvVar struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type PortSpec struct {
	Name          string `json:"name,omitempty" yaml:"name,omitempty"`
	ContainerPort int32  `json:"containerPort" yaml:"containerPort" validate:"required,gt=0,lt=65536"`
	Protocol      string `json:"protocol,omitempty" yaml:"protocol,omitempty" validate:"omitempty,oneof=TCP UDP SCTP"`
}

type ResourceSpec struct {
	Requests CPUAndMemory `json:"requests,omitempty" yaml:"requests,omitempty"`
	Limits   CPUAndMemory `json:"limits,omitempty" yaml:"limits,omitempty"`
}

type CPUAndMemory struct {
	CPU    string `json:"cpu,omitempty" yaml:"cpu,omitempty"`
	Memory string `json:"memory,omitempty" yaml:"memory,omitempty"`
}
